package org.bee.audit;

import org.bee.enums.IsDelete;
import org.bee.secuirty.context.CurrentUser;
import org.bee.secuirty.model.UserInfo;
import org.springframework.beans.BeanUtils;

import java.util.Date;

/**
 * 审计字段
 */
public class AuditUtils {

    /**
     * 新增时审计字段赋值
     * @param obj 数据实体
     */
    public static void InsertInfo(Object obj) {
        if (obj == null) {
            return;
        }
        UserInfo user = CurrentUser.getUser();
        AuditModel auditModel = new AuditModel();
        auditModel.setIsDeleted(Boolean.valueOf(IsDelete.FALSE.getCode()));
        auditModel.setCreateTime(new Date());
        if(null!=user){
            auditModel.setCreateUser(user.getUserId());
        }
        BeanUtils.copyProperties(auditModel, obj);
    }

}
